<template>
  <div>
    <template>
      <Card style="width:850px;margin: auto;">
        <Form :model="formLeft" label-position="left" :rules="validateLibForm" :label-width="100" style="width: 300px;margin: auto;">

          <FormItem label="产品代码:" prop="code">
            <Input v-model="formLeft.code" :maxlength="10"/>
          </FormItem>

          <FormItem label="描述:" prop="description">
            <Input v-model="formLeft.description" :maxlength="100" type="textarea" style="width: 200px"/>
          </FormItem>

          <FormItem label="路线:" prop="routing">
            <Input v-model="formLeft.routing" :maxlength="50"/>
          </FormItem>

          <row type="flex" justify="center">
            <i-col span="20">

            </i-col>
            <i-col span="30">
              <Button type="primary" @click="ProductInsert">添加</Button>
              <Button type="success" style="margin-left: 160px" @click="back">返回</Button>
            </i-col>
          </row>

        </Form>
      </Card>
    </template>
  </div>
</template>

<script>
  import {ProductInsert} from "../../../api/data"

  export default {
    data() {
      return {
        formLeft: {
          code: '',
          description: '',
          routing: ''
        },
        validateLibForm: {
          code: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          description: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          routing: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
        }
      }
    },
    mounted() {

    },
    methods: {
      ProductInsert() {
        if (this.formLeft.code !== null && this.formLeft.code !== "") {
          if (this.formLeft.description !== null && this.formLeft.description !== "") {
            if (this.formLeft.routing !== null && this.formLeft.routing !== "") {
              ProductInsert(this.formLeft).then(res => {
                this.$Message.success("添加成功");
                this.$router.go(-1)
              })
            } else {
              this.$Message.error("路线不能为空");
            }
          } else {
            this.$Message.error("描述不能为空");
          }
        } else {
          this.$Message.error("产品代码不能为空");
        }
      },
      back() {
        this.$router.go(-1);
      },

    }
  }
</script>


